package yxy.game.pm2.command.shop;

import yxy.cherry.game.base.message.MessageEmitterHandler;
import yxy.cherry.game.base.message.annotation.MessageSource;
import yxy.cherry.game.base.message.annotation.MessageType;
import yxy.game.pm2.Result;
import yxy.game.pm2.command.Command;
import yxy.game.pm2.message.ShopMessage;
import yxy.game.pm2.module.shop.handle.CreditRobShopHandle;

/** 商店 积分夺宝商店 */
@MessageType(proto = Command.CreditRobShop, classtype = ShopMessage.CreditRobShopRequest.class)
public class CMD_CreditRobShop extends Command<ShopMessage.CreditRobShopRequest> {

	@Override
	public void execute(MessageSource messageSource, ShopMessage.CreditRobShopRequest request) {
		try {
			String playerCode = messageSource.getTag();

			ShopMessage.CreditRobShopResponse.Builder response = ShopMessage.CreditRobShopResponse.newBuilder();

			new CreditRobShopHandle().packResponse(playerCode, response);

			//根据开服时间和showtime过滤商品是否展示
			response.addAllGoods(new CreditRobShopHandle().checkShopItemIsShow(playerCode));

			send(messageSource, response, Result.Success);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	private void send(MessageSource messageSource, ShopMessage.CreditRobShopResponse.Builder response, Result result) {
		response.setResult(result.packResult());
		MessageEmitterHandler.getInstance().send(messageSource, response.build());
	}
}